<?php
namespace app\mobile\controller;
use think\Controller;
use think\Controllers;
use think\Session;
use think\Cookie;
use think\Jump;
use think\Db;
class Bank extends Controllers{

	public function index(){
	$member = Session::get("user");
		//获取幻灯片
	$huan1=DB::query("SELECT * FROM  ims_xuan_zy_huan  where status=1 and type='信用卡' and uniacid=2 order by rank desc");

    //查询用户等级
    $sql ="select level from ims_xuan_zy_person where uid = '{$member['uid']}'";
    $level = DB::query($sql)[0]['level'];
	//查询幻灯项目
	$huan=DB::query("SELECT * FROM ims_xuan_zy_bank where status=1 and tuijian=1 and uniacid=2 order by rank desc");

	//查询所有发布的项目
	$list=DB::query("SELECT * FROM  ims_xuan_zy_bank where status=1 and uniacid=2  order by rank desc");
     $id  = $member['uid'];
        $sql = "SELECT mobile from ims_xuan_zy_person where uid = '{$id}'";
        $user = DB::query($sql)[0];
        if ($user) {
            $type = 1;
        } else {
            $type = 0;
        }
        $data['huan1'] = $huan1;
        $data['level'] = $level;
        $data['huan'] = $huan;
        $data['list'] = $list;
        $data['type'] = $type;
        echo json_encode($data);die;
	}
	public function detail(){
		$id=$_REQUEST['id'];
		$item=DB::query("SELECT * FROM  ims_xuan_zy_bank where status=1 and id='{$id}'")[0];

        if(empty($item)){
            // $item=DB::query("SELECT * FROM  ims_xuan_zy_bank where  id={$id}");
            include $this->error('该银行暂未开放');die;
        }

		$item['content']=json_decode($item['content'],1);
            $id  = $_SESSION['uid'];
            $sql = "SELECT mobile from ims_xuan_zy_person where uid = '{$id}'";
            $user = DB::query($sql)[0];
            if ($user['mobile']) {
                $type = 1;
            } else {
                $type = 0;
            }
            $data['item'] = $item;
            $data['type'] = $type;
            echo json_encode($data);die;
	}
	public function gotourl(){
			$member = Session::get("user");
			$id=$_REQUEST['id'];
            $applicant_id=$_REQUEST['applicant_id'];
			$item=DB::query("SELECT * FROM  ims_xuan_zy_bank where status=1 and id='{$id}'")[0];
            $person=DB::query("SELECT * FROM ims_xuan_zy_proposer where uid='{$member['uid']}' and id= '{$applicant_id}'")[0];
            //等级信息
            $upsuer=DB::query("select * from ims_xuan_zy_userup where uid = '{$member['uid']}'")[0];

            $unionque=DB::query("SELECT * FROM ims_xuan_zy_bankorder where mobile='{$person['mobile']}' and uniacid=2 and bank_id='{$item['id']}'")[0];

            //检测是否其他账号用这个手机号申请过
            if($unionque){
                if($unionque['user_id']==$member['uid']){
                    //是自己申请过直接转跳

                    echo json_encode(array('status'=>1,'url'=>$item['url']));die;
                }else{
                    //别人申请过阻止

                    echo json_encode(array('status'=>0,'info'=>'手机号已经存在其他账号注册','url'=>$item['url']));die;
                }




            }else{
                //没有任何人申请过
                $data=array(
                    'user_id'=>$member['uid'],
                    'bank_id'=>$item['id'],
                    'suid'=>$upsuer['suid'],
                    'ssuid'=>$upsuer['ssuid'],
                    'sssuid'=>$upsuer['sssuid'],

                    'mobile'=>$person['mobile'],
                    'bank_name'=>$item['bankname'],
                    'hide_name'=>$person['name'],

                    'idcard'=>$person['idcard'],
                    'status'=>1,
                    'create_time'=>date('Y-m-d H:i:s',time()),
                    'uniacid'=>$_W['uniacid']
                );
                $sql = "select uid from ims_xuan_zy_bankorder where bank_name = '{$item['bankname']}' and idcard = '{$person['idcard']}'";
                $res = DB::query($sql)[0];
                if($res['uid'])
                {
                echo json_encode(array('status'=>1,'info'=>'添加成功','url'=>$item['url']));die;
                }
                $result = DB::table("ims_xuan_zy_bankorder")->insert($data);
                /*增加通知*/
                // if($result){
                //     $iiid = pdo_insertid();
                //     $item1=pdo_get('xuan_zy_bankorder',['id'=>$iiid]);
                //     fenyong3(100,$item1,1,$config);
                // }

                echo json_encode(array('status'=>1,'info'=>'添加成功','url'=>$item['url']));die;
            }


	}
}